package twu.shubham.library;


public class Library {

    private int totalMovies = 15;
    private int totalBooks =5;
    private MovieRecord[] movieList = new MovieRecord[totalMovies];
    private BookRecord[]  bookList =new BookRecord[totalBooks];
    private int totalMembers = 5;
    private int loginStatus = 0;
    private int loginId = 0;

    private MembersRecord[] membersList = new MembersRecord[totalMembers];

    public Library()
    {
           movieValues(movieList);
           bookValues(bookList);
        membersValues(membersList,totalMembers);
    }


    public String bookPrint()
    {
        String allBooks = "";
        for(int i=0; i<totalBooks;i++)
        {
        if(bookList[i].bookName.length() > 0)
        {
           allBooks = allBooks + (i+1 +"\t\t" + bookList[i].bookName+"\n");
        }
        }
        return allBooks;
    }

    public String moviePrint() {

        String allMovies = "";
        for(int i=0; i<totalMovies;i++)
        {
        if((movieList[i].movieName.length()) > 0)
        {
            allMovies = allMovies +(i+1) + movieList[i].movieDetails();
        }
        }
        return allMovies;
    }

    public String reserveBook(int serialNo)
    {
        if(loginStatus==1)
        {

            if(serialNo<=totalBooks && serialNo-1>=0)
            {
                if(bookList[serialNo-1].bookName.length() > 0)
                    return ("Thank You, Your book has been reserved");
                return ("Not a Valid Book Number");
            }

            else
            {
                return ("Sorry, this book is not available yet");
            }
        }

        else
        {
            return ("Login First !!!");
        }

    }

    public String getMembershipDetail() {

        if(loginStatus==0)
        {
            return ("Login First !!!");
        }

        else
        {
            int done=0;
            int i;
            for(i=0;i<totalMembers && done==0;i++)
            {
                if(membersList[i].libraryNumber==loginId)
                {
                    done=1 ;
                }
            }
            return membersList[i-1].printDetail();
        }
    }

    public String Login(int libraryNumber, String password) {

        if(loginStatus==0)
        {
            for(int i=0;i<totalMembers && loginStatus==0;i++)
            {
                if(membersList[i].libraryNumber==libraryNumber)
                {
                    int a = membersList[i].checkForPassword(password);
                    if(a==1)
                    {
                        loginStatus=1;
                        loginId=libraryNumber;
                    }
                }


            }
            if(loginStatus==0)
            {
                return ("Either Wrong library number or Password");
            }
            else
                return ("You are logged in");
        }
        else
            return ("Already Logged in");


    }

    private static void movieValues(MovieRecord[] movieList) {

        movieList[0] = new MovieRecord("Sholay",1975,"R.Sippy",7);
        movieList[1] = new MovieRecord("Guide",2008,"R.Mehra",7);
        movieList[2] = new MovieRecord("Satya",1976,"P.Sippy",7);
        movieList[3] = new MovieRecord("Tiranga",1977,"S.Sippy",7);
        movieList[4] = new MovieRecord("Anand",1978,"T.Sippy",7);
        movieList[5] = new MovieRecord("Aamir",2008,"R.Mehra",7);
        movieList[6] = new MovieRecord("Chennai",2008,"R.Mehra",7);
        movieList[7] = new MovieRecord("Express",2008,"R.Mehra",7);
        movieList[8] = new MovieRecord("Dabbang",2008,"R.Mehra",7);
        movieList[9] = new MovieRecord("Wanted",2008,"R.Mehra",7);
        movieList[10] = new MovieRecord("Players",2008,"R.Mehra",7);
        movieList[11] = new MovieRecord("Black",2008,"R.Mehra",7);
        movieList[12] = new MovieRecord("xyzzz",2008,"R.Mehra",7);
        movieList[13] = new MovieRecord("Maachis",2008,"R.Mehra",7);
        movieList[14] = new MovieRecord("Krati",2008,"R.Mehra",7);


    }

    private void bookValues(BookRecord[] bookList) {
        bookList[0] = new BookRecord(2,"a");
        bookList[1] = new BookRecord(0,"b");
        bookList[2] = new BookRecord(1,"c");
        bookList[3] = new BookRecord(2,"d");
        bookList[4] = new BookRecord(4,"e");
    }

    private static void membersValues(MembersRecord membersList[],int totalMembers) {

        membersList[0]= new MembersRecord(1111111,"Amit","551122","amit@gmail.com") ;
        membersList[1]= new MembersRecord(1111112,"Ankit","554432","ankit@gmail.com") ;
        membersList[2]= new MembersRecord(1111113,"Rohit","554434","rohit@gmail.com") ;
        membersList[3]= new MembersRecord(1111114,"Abhi","554433","abhi@gmail.com") ;
        membersList[4]= new MembersRecord(1111115,"Ankita","554436","ankita@gmail.com") ;
        for(int i = 0;i<totalMembers;i++)
        {
            membersList[i].passwordGenerator();
        }
    }



}
